﻿//-----------------------------------------------------------------------
// <copyright file="IInstallationStage.cs" author="Artak Mkrtchyan">
//     Creative Commons - GNU General Public License (http://creativecommons.org/licenses/GPL/2.0/
// </copyright>
// <author>Artak Mkrtchyan</author>
// <email>mkArtak@gmail.com</email>
// <date>20/03/2013</date>

using System.Threading.Tasks;

namespace AppUpdateInstaller.Model
{
	public delegate void InstallationStageProgressEventHandler(IInstallationStage argSender, InstallationStageProgressEventArgs argEA);

	/// <summary>
	/// Represents a contract for defining the installation stage.
	/// The installation process is a sequence of installation stages - coming in the predefined order
	/// </summary>
	public interface IInstallationStage
	{
		event InstallationStageProgressEventHandler ProgressChanged;

		/// <summary>
		/// Runs the installation stage
		/// </summary>
		void Run();

		Task RunAsync();

		/// <summary>
		/// Gets a boolean value indicating, whether the installation stage supports rollback or not
		/// </summary>
		bool SupportsRollback { get; }

		void RollBack();

		/// <summary>
		/// Rolls the installation stage back to the stage, where the stage has not been run.
		/// The RollBack will be ignored, if the stage haven't been run yet.
		/// If the <see cref="SupportsRollback"/> property value is false, the method call will throw a <see cref="NotSupportedException"/>
		/// </summary>
		Task RollBackAsync();

		/// <summary>
		/// Gets a boolean value indicating, whether current installation stage has a post-installation step registered for run.
		/// </summary>
		bool HasFinalizerStage { get; }

		/// <summary>
		/// Executes the post-installation step of the installation stage
		/// Consider calling the method after ensuring the <see cref="HasFinalizerStage"/> property value is true.
		/// Otherwise an <see cref="InstallationStageException"/> will be thrown
		/// </summary>
		/// <exception cref="InstallationStageException">Thrown, if the HasFinalizerStage property value is false</exception>
		void FinalizeStage();
	}
}
